package drinkkiosk.buttons;

import drinkkiosk.cards.SendCard;
import drinkkiosk.cards.UnlockCard;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;

/**ClearButton sets the TableNumber to the default value 000. 000 is not a valid
 * Number so a Drink cannot be sent until the number is changed.
 * If the ClearButton is used with the UnlockCard, it clears the keycode as well.
 *
 * @author Charles Ritchea
 */
public class ClearButton extends JButton implements ActionListener{
	/**ClearButton() sets the button text to "Clear"
	 */
	public ClearButton() {
		super("Clear");
		setFont(new java.awt.Font("Arial", 0, 48));
		addActionListener(this);	
	}
	/**Determines the context of the event and sets all displayed numbers to 0
	 * @param e ActionEvent the event of pressing the ClearButton
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		JButton button = (JButton)e.getSource();
		JPanel numPanel = (JPanel)button.getParent();
		JLayeredPane layeredPane = (JLayeredPane)numPanel.getParent();
		JPanel card = (JPanel)layeredPane.getParent();
		if(card instanceof SendCard){
			SendCard sendCard = (SendCard)card;
			sendCard.clearTableNumber();
		} else if (card instanceof UnlockCard) {
			UnlockCard unlockCard = (UnlockCard)card;
			unlockCard.clearTableNumber();
		}
	}
}